package com.javayh.controller;

import com.javayh.server.IConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author Dylan Yang
 * @Title: TestController
 * @ProjectName demo
 * @Description: TODO
 * @date 2018/11/189:45
 */
@RestController
public class TestController implements IConsumerService {

    @Autowired
    private RestTemplate restTemplate;

    @Value(value = "${server.port}")
    private String port;

    @GetMapping(value = "getRegister")
    public String getRegister(){
        String url = "http://register/getTest";
        String result = restTemplate.getForObject(url, String.class);
        return result;
    }

    @Override
    public String getUserInfo() {
        System.out.println(" 我是会员服务,会员服务调用订单服务开始啦！！");
        try {
            // 会员服务接口产生1.5秒的延迟
            Thread.sleep(1500);
        } catch (Exception e) {
            // TODO: handle exception
        }
        return "订单服务接口调用会员服务接口成功------->调用的端口为："+port;
    }
}

